package com.example.administrator.kaohedemo.Utils;

import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

/**
 * Created by Administrator on 2016/6/23.
 */
public class HttpUtils {

    private static HttpUtils httpUtils;

    public static HttpUtils getInstense(){
        if (httpUtils==null){
            httpUtils=new HttpUtils();
        }
        return httpUtils;
    }

    public String getResult(String path){
        return FindInHttp(path,"GET");
    }

    private String FindInHttp(String path,String Method){
        String result="";
        try {
            URL url =new URL(path);
            HttpURLConnection conn = (HttpURLConnection)url.openConnection();
            conn.setConnectTimeout(5*1000);
            conn.setRequestMethod(Method);
            InputStream inStream = conn.getInputStream();
            byte[] data = StreamTool.stream2Byte(inStream);
            result = new String(data, "UTF-8");
        }catch (Exception e){
            e.toString();
        }
        return result;
    }
}
